package com.butterfly.hotkey.dashboard.framework.netty.handler;

import com.butterfly.hotkey.common.factory.CommonFactoryBean;
import com.butterfly.hotkey.common.netty.INettyMsgHandler;
import com.butterfly.hotkey.core.constant.Constants;
import com.butterfly.hotkey.core.constant.MsgTypeConst;
import com.butterfly.hotkey.core.model.msg.HotKeyMsg;
import com.butterfly.hotkey.core.util.NettyMsgUtil;
import io.netty.channel.ChannelHandlerContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import static com.butterfly.hotkey.dashboard.constant.FactoryConstant.HANDLER;
import static com.butterfly.hotkey.core.constant.MsgTypeConst.PING;

/**
 * 心跳包处理
 *
 * @author butterfly
 */
@Component
@CommonFactoryBean(type = HANDLER, valueInt = PING)
public class HeatBeatNettyMsgHandler implements INettyMsgHandler {

    private static final Logger log = LoggerFactory.getLogger(Constants.DASHBOARD);

    @Override
    public void handle(HotKeyMsg message, ChannelHandlerContext ctx) {
        ctx.writeAndFlush(NettyMsgUtil.buildByteBuf(new HotKeyMsg(MsgTypeConst.PONG)));
    }
}
